/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bean;

import Action.TimeSetSessionBeanLocal;
import Entity.TimeSet;

import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Cyrax
 */
@ManagedBean
@SessionScoped
public class TimeSetBean {

    @EJB
    private TimeSetSessionBeanLocal timeSetSessionBean;
    private TimeSet ts;
    private List<TimeSet> tis;
    private TimeSet selectTime;

    /** Creates a new instance of TimeSetBean */
    public TimeSetBean() {
        ts = new TimeSet();
    }

    /**
     * @return the ts
     */
    public TimeSet getTs() {
        return ts;
    }

    /**
     * @param ts the ts to set
     */
    public void setTs(TimeSet ts) {
        this.ts = ts;
    }

    //list all
    public List<TimeSet> getListAllTimeSet() {

        tis = timeSetSessionBean.listAllTimeSet();
        return tis;

    }
    //add new

    public void insertTimeSet() {
        try {

            if (ts.getHoursStart() == null) {
                System.out.println("Start is not null!!!");

            } else {
                timeSetSessionBean.addTimeSet(ts);
            }

        } catch (Exception ex) {
            System.out.println("Error : " + ex.getMessage());
        }
    }

    //Update
    public void updateTimeSet() {

        int tsId = selectTime.getTsID();

        System.out.println("Xem Id:" + tsId);

        timeSetSessionBean.updateTimeSet(tsId, selectTime.getHoursStart(), selectTime.getHoursEnd());
//        timeSetSessionBean.upTimeSet(selectTime);

    }

    //Delete
    public void DeleteTimeSet(TimeSet ts) {
        try {

            timeSetSessionBean.DeleteTimeSet(ts);
        } catch (Exception e) {
            System.out.println("Error : " + e.getMessage());
        }
    }

    /**
     * @return the selectTime
     */
    public TimeSet getSelectTime() {
        return selectTime;
    }

    /**
     * @param selectTime the selectTime to set
     */
    public void setSelectTime(TimeSet selectTime) {
        this.selectTime = selectTime;
    }
}
